package com.yang.action;

import com.yang.entity.Address;
import com.yang.service.AddressService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/saveAddress")
public class AddressSaveAction extends HttpServlet {
    AddressService addressService = new AddressService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Address address = new Address();
        String contacts = req.getParameter("contacts");
        address.setContacts(contacts);
        String addres = req.getParameter("address");
        address.setAddress(addres);
        String tel = req.getParameter("tel");
        address.setTel(tel);
        String userid = req.getParameter("userid");
        address.setUserid(Integer.parseInt(userid));
        String def = req.getParameter("def");
        address.setDef(Integer.parseInt(def));
        int num = addressService.saveAddress(address);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

